#pragma once
#ifndef myHelper_h__
#define myHelper_h__


#include "./adapter/myAdapterType.h"
#include "./common/myADT.h"
class myHelper
{
public:
	inline static Bool isRectIntersect(myRect* rect1,myRect* rect2)
	{
		if(rect1->x + rect1->w - 1< rect2->x) return vFalse;
		if(rect2->x + rect2->w - 1< rect1->x) return vFalse;
		if(rect1->y + rect1->h - 1 < rect2->y) return vFalse;
		if(rect2->y + rect2->h - 1< rect1->y) return vFalse;
		return vTrue;
	}
	inline static myRect* combineRects(myRect* outRect,myRect* rect1,myRect* rect2)
	{
		i32 x1,y1,x2,y2;
		x1 = rect1->x;
		y1 = rect1->y;
		x2 = rect2->x;
		y2 = rect2->y;

		outRect->x = x1 < x2 ? x1 : x2;
		outRect->y = y1 < y2 ? y1 : y2;

		x1 += rect1->w;
		y1 += rect1->h;
		x2 += rect2->w;
		y2 += rect2->h;

		outRect->w = x1 > x2 ? (x1 - outRect->x) : (x2 - outRect->x);
		outRect->h = y1 > y2 ? (y1 - outRect->y) : (y2 - outRect->y);

		return outRect;
	}
	inline static Bool isRect1InRect2(myRect* rect1,myRect* rect2)
	{
		if( rect1->x >= rect2->x && (rect1->x + rect1->w) <= (rect2->x + rect2->w) &&
			rect1->y >= rect2->y && (rect1->y + rect1->h) <= (rect2->y + rect2->h))
			return vTrue;
		return vFalse;
	}
	inline static Bool isRect1EqualRect2(myRect* rect1,myRect* rect2)
	{
		if( rect1->x == rect2->x && rect1->y == rect2->y &&
			rect1->h == rect2->h && rect1->w == rect2->w)
			return vTrue;
		return vFalse;
	}
	inline static myRect* translationRect(myRect* out,myRect* in,myRect* trans)
	{
		out->x = in->x + trans->x;
		out->y = in->y + trans->y;
		out->h = in->h;
		out->w = in->w;
		return out;
	}

	inline static Bool isPointInRect(Point& pos,myRect* rect)
	{
		if(pos.x >= rect->x && pos.x <= rect->x + rect->w &&
			pos.y >= rect->y && pos.y <= rect->y + rect->h)
			return vTrue;
		return vFalse;
	}
};


#endif // myHelper_h__
